package com.snpic.appaw.module.third.controller.admin.sms;

import com.snpic.appaw.framework.common.pojo.CommonResult;
import com.snpic.appaw.module.third.controller.admin.sms.vo.SmsReqVO;
import com.snpic.appaw.module.third.controller.admin.sms.vo.SmsRespVO;
import com.snpic.appaw.module.third.service.sms.SmsService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.annotation.security.PermitAll;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.support.ResourcePatternResolver;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import static com.snpic.appaw.framework.common.pojo.CommonResult.error;
import static com.snpic.appaw.framework.common.pojo.CommonResult.success;
import static com.snpic.appaw.framework.common.util.collection.CollectionUtils.convertList;

@Tag(name = "第三方调用 - 短信")
@RestController
@RequestMapping("/third/sms")
@Validated
@Slf4j
public class SmsController {

    @Resource
    private SmsService smsService;
	@Autowired
	private ResourcePatternResolver resourcePatternResolver;

    @PostMapping("/sendSms")
    @Operation(summary = "单条发送短信")
    @PermitAll
		public CommonResult<SmsRespVO> sendSms(@RequestBody SmsReqVO reqVO){
        log.info("Entered into thrid-server/SmsController/sendSms(),the param reqVO={}",reqVO);
        SmsRespVO smsRespVO = smsService.sendSmsOne(reqVO);
        if(smsRespVO.getReplyCode().equals("0000")){
            return success(smsRespVO,"发送短信成功");
        }else{
            return error(Integer.parseInt(smsRespVO.getReplyCode()),smsRespVO.getReplyDescription());
        }
    }

}
